package com.whfc.ms.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppTrainingCategoryDTO;
import com.whfc.emp.param.AppTrainingCategoryAddParam;
import com.whfc.emp.param.AppTrainingCategoryEditParam;
import com.whfc.emp.param.AppTrainingCategoryListParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsTrainingCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 人员管理-培训人员学习列表
 *
 * @author realm
 * @Description:
 */
@RestController
@RequestMapping("/ms/api/trainingStudy")
public class AppTrainingUserStudyController extends BaseController {
    @Autowired
    private MsTrainingCategoryService msTrainingCategoryService;

    /**
     * 人员管理-培训列表
     *
     * @param user
     * @param request
     * @param startDate
     * @param endDate
     * @return
     */
    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated AppTrainingCategoryListParam request,
                       @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                       @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        request.setStartTime(startDate);
        request.setEndTime(endDate);
        logger.info("人员管理-培训列表，loginer:{},AppTrainListParam:{}", user.getUsername(), request.toString());
        PageData<AppTrainingCategoryDTO> pageData = msTrainingCategoryService.list(request);
        return ResultUtil.success(pageData);
    }

    /**
     * 人员管理- 新增培训
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/train/add")
    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppTrainingCategoryAddParam request) {
        logger.info("人员管理-增加培训，loginer:{},AppTrainingCategoryAddParam:{}", user.getUsername(), request.toString());
        msTrainingCategoryService.add(request);
        return ResultUtil.success();
    }


    /**
     * 人员管理-编辑培训
     *
     * @param user
     * @param request
     * @return
     */
    @RequiresPermissions("emp/train/edit")
    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody AppTrainingCategoryEditParam request) {
        logger.info("人员管理-编辑培训，loginer:{},AppTrainEditParam:{}", user.getUsername(), request.toString());
        msTrainingCategoryService.edit(request);
        return ResultUtil.success();
    }


    /**
     * 人员管理-删除培训
     *
     * @param user
     * @param trainId
     * @return
     */
    @RequiresPermissions("emp/train/del")
    @PostMapping("/del/{trainId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @PathVariable("trainId") Integer trainId) {
        logger.info("人员管理-删除培训,loginer:{},trianId:{}", user.getUsername(), trainId);
        msTrainingCategoryService.del(trainId);
        return ResultUtil.success();

    }



}
